package cn.chenyumeng.blog.controller.blog;

import cn.chenyumeng.blog.dto.*;
import cn.chenyumeng.blog.service.blog.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: blog->CommonController
 * @description:
 * @author: cg
 * @create: 2020-08-11 11:39
 **/
@Validated
@RestController
@ResponseBody
@RequestMapping("/blog/common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @GetMapping("/getAllUser")
    public CommonResponse getAllUser() {
        List<UserDTO> list = commonService.queryAllUser();
        if (list == null) {
            return CommonResponse.build(ResultCode.PARAM_IS_INVALID);
        }
        return CommonResponse.ok(list);
    }

    @GetMapping("/getAllType")
    public CommonResponse getAllType() {
        List<TypeDTO> list = commonService.queryAllType();
        if (list == null) {
            return CommonResponse.build(ResultCode.PARAM_IS_INVALID);
        }
        return CommonResponse.ok(list);
    }

    @GetMapping("/getAllTag")
    public CommonResponse getAllTag() {
        List<TagDTO> list = commonService.queryAllTag();
        if (list == null) {
            return CommonResponse.build(ResultCode.PARAM_IS_INVALID);
        }
        return CommonResponse.ok(list);
    }

}
